﻿using System;
using System.Data;
using System.Linq;
using System.Windows;
using WPFExcelReport.Chart;
using System.Windows.Controls;
using WPFExcelReport.Helpers;
using System.ComponentModel;
using ReflectionStudio.Core.Events;
namespace WPFExcelReport
{
    /// <summary>
    /// Interaction logic for EditEventWindow.xaml
    /// </summary>
    public partial class TVKPOS : UIVKPOS
    {
        public TVKPOS()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            MV = new VVKPOS();
            this.DataContext = MV;
            MESSAGES += "VKKNEW;VVRELOAD;VVTCHG;VKPCHK;WDCHG;";
            VKPSA = "  ";
            InitializeComponent();

        }
        public override void VKKLOAD(DataRow _dwVKK)
        {
            if (KRS.Length < 1)
                return;
            SResult = TMV.VVVKP(KRS, LFD, LIEFSCH); 
            MergeData(SResult, false);
            if (IsAuto)
            {
                if (TBMain.Rows.Count == 0)
                    NewCommand(null, null);
            } 
        }
        public override void VKPCHK(MessageInfo msg)
        {
            SResult = TMV.VVVKP(KRS, LFD, LIEFSCH);
            filter = "VKPAUFKRS='" + msg.KRS + "' AND VKPAUFLFD='" + msg.LFD + "' AND VKPAUFPOS='" + msg.POS + "'";
            rows = SResult.Tables[0].Select(filter);
            var query = from DataRow row in TBMain.AsEnumerable()
                        where row["VKPAUFKRS"].ToString() == msg.KRS
                        && row["VKPAUFLFD"].ToString() == msg.LFD
                        && row["VKPAUFPOS"].ToString() == msg.POS
                        select row;
            foreach (DataRow row in query)
            {
                row.ItemArray = rows[0].ItemArray;
            }
            base.VKPCHK(msg);
        }
        public override void PRODREQ()
        {
            base.PRODREQ();
            switch (ARTST)
            {
                case "F":
                     TMV.WDLOAD(dwVKP);
                    break;
            }
        } 
    }

}
